﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using BLL;
using HighLowGameBLL;

/// <summary>
/// Summary description for WSGame
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class WSGame : System.Web.Services.WebService
{

    public WSGame()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public int GameConfigUpdate(int id, double minimumBet, double maximumBet, double rate, double randomRate,
        int startExtraLife, int extraLife, int maximumExtraLife,
        int startOutOf, int outOf, int maximumOutOf,
        int startNudges, int nudges, int maximumNudges,
        int startFreeSpin, int freeSpin, int maximumFreeSpin)
    {
        string function = HttpContext.Current.Request.Headers["Referer"].Substring(HttpContext.Current.Request.Headers["Referer"].LastIndexOf("/") + 1);
        int p = CtrAdmin.GetPermission(function);
        if ((p & (int)Config.EnumPermission.Edit) != (int)Config.EnumPermission.Edit)
            return -1;
        var ctr = new CtrHiLoGame();
        int result = ctr.UpdateGame(id: id, name: null, minimumValue: null, maximumValue: null, minimumBet: minimumBet, maximumBet: maximumBet
            , rate: rate, randomRate: randomRate,
            startExtraLife: startExtraLife, startOutOf: startOutOf, startNudges: startNudges, startFreeSpin: startFreeSpin,
            extraLife: extraLife, outOf: outOf, nudges: nudges, freeSpin: freeSpin
            , maximumExtraLife: maximumExtraLife, maximumOutOf: maximumOutOf, maximumNudges: maximumNudges, maximumFreeSpin: maximumFreeSpin
            , jackpotMinBetAu: null, jackpotAu: null, jackpotBlockAu: null, jackpotjumpAu: null
            , jackpotMinBetAg: null, jackpotAg: null, jackpotBlockAg: null, jackpotjumpAg: null
            , jackpotStatusAu: null, jackpotStatusAg: null,
            maximumJackpotAu: null, maximumJackpotAg: null,
            jackpotStartAu: null, jackpotStartAg: null);
        if (result > 0)
        {
            string des = "Cập nhật cấu hình game: [id: " + id + ", minimumBet: " + minimumBet + ", maximumBet: " +
                         maximumBet + ", rate: " + rate + ", randomRate: " + randomRate
                         + ", startExtraLife: " + startExtraLife + ", extraLife: " + extraLife + "-" + maximumExtraLife
                         + ", startOutOf: " + startOutOf + ", outOf: " + outOf + "-" + maximumOutOf
                         + ", startNudges: " + startNudges + ", nudges: " + "-" + maximumNudges
                         + ", startFreeSpin: " + startFreeSpin + ", freeSpin: " + freeSpin + "-" + maximumFreeSpin +
                         " ]";
            CtrLog.InsertLog(Config.LogActionConstants.Modify, des, function);
        }
        return result;
    }

    [WebMethod]
    public int JackPortUpdate(int id,
            double jackpotMinBetAu,
            double jackpotBlockAu,
            double jackpotJumpAu,
            double jackpotStartAu,
            int jackpotStatusAu,
            double jackpotMinBetAg,
            double jackpotBlockAg,
            double jackpotJumpAg,
            double jackpotStartAg,
            int jackpotStatusAg,
            double maximumJackpotAu,
            double maximumJackpotAg)
    {
        jackpotMinBetAu = Math.Round(jackpotMinBetAu, 3);
        jackpotBlockAu = Math.Round(jackpotBlockAu, 3);
        jackpotJumpAu = Math.Round(jackpotJumpAu, 3);
        jackpotStartAu = Math.Round(jackpotStartAu, 3);
        maximumJackpotAu = Math.Round(maximumJackpotAu, 3);

        jackpotMinBetAg = Math.Round(jackpotMinBetAg, 3);
        jackpotBlockAg = Math.Round(jackpotBlockAg, 3);
        jackpotJumpAg = Math.Round(jackpotJumpAg, 3);
        jackpotStartAg = Math.Round(jackpotStartAg, 3);
        maximumJackpotAg = Math.Round(maximumJackpotAg, 3);
        string function = HttpContext.Current.Request.Headers["Referer"].Substring(HttpContext.Current.Request.Headers["Referer"].LastIndexOf("/") + 1);
        int p = CtrAdmin.GetPermission(function);
        if ((p & (int)Config.EnumPermission.Edit) != (int)Config.EnumPermission.Edit)
            return -1;
        CtrHiLoGame ctr = new CtrHiLoGame();

        int result = ctr.UpdateGame(id: id, name: null, minimumValue: null, maximumValue: null, minimumBet: null, maximumBet: null
            , rate: null, randomRate: null,
            startExtraLife: null, startOutOf: null, startNudges: null, startFreeSpin: null,
            extraLife: null, outOf: null, nudges: null, freeSpin: null
            , maximumExtraLife: null, maximumOutOf: null, maximumNudges: null, maximumFreeSpin: null
            , jackpotMinBetAu: jackpotMinBetAu, jackpotAu: null, jackpotBlockAu: jackpotBlockAu, jackpotjumpAu: jackpotJumpAu
            , jackpotMinBetAg: jackpotMinBetAg, jackpotAg: null, jackpotBlockAg: jackpotBlockAg, jackpotjumpAg: jackpotJumpAg
            , jackpotStatusAu: jackpotStatusAu, jackpotStatusAg: jackpotStatusAg,
            maximumJackpotAu: maximumJackpotAu, maximumJackpotAg: maximumJackpotAg,
            jackpotStartAu: jackpotStartAu, jackpotStartAg: jackpotStartAg);

        if (result > 0)
        {
            string des = "Cập nhật cấu hình jackport:  [id: " + id + ", jackpotMinBetAu: " + jackpotMinBetAu + ", jackpotBlockAu: " + jackpotBlockAu + ", jackpotJumpAu: " + jackpotJumpAu + ", jackpotStartAu: " + jackpotStartAu + ", jackpotStatusAu: " + jackpotStatusAu
             + ", jackpotMinBetAg: " + jackpotMinBetAg + ", jackpotBlockAg: " + jackpotBlockAg + ", jackpotJumpAg: " + jackpotJumpAg + ", jackpotStartAu: " + jackpotStartAu + ", jackpotStatusAg: " + jackpotStatusAg + ", maximumJackpotAu: " + maximumJackpotAu + ", maximumJackpotAg: " + maximumJackpotAg + " ]";
            CtrLog.InsertLog(Config.LogActionConstants.Modify, des, function);
        }
        return result;
    }

}
